package com.exchange.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exchange.entity.pojo.CardDisplay;
import com.exchange.entity.vo.CouponVo;
import com.exchange.mapper.CardDisplayMapper;
import com.exchange.service.CardDisplayService;
import com.exchange.until.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Type;

/**
 * @author 周佳辉
 * @date 2024/5/9
 */
@RestController
@RequestMapping("/manager")
@Tag(name = "添加优惠卷")
public class CouponController {

    @Autowired
    private CardDisplayService cardDisplayService;

    @GetMapping("/couponlist")
    @Operation(summary = "优惠卷列表")
    public Result couponlist(@RequestParam(value = "offset",defaultValue = "1")Integer offset,
                             @RequestParam(value = "pagesize",defaultValue = "10")Integer pagesize,
                             @RequestParam(value = "type",defaultValue = "",required = false)Integer type){
        System.err.println(type);
        Page<CardDisplay> page = cardDisplayService.pages(offset,pagesize, type);
        return Result.success(page);
    }

    @Operation(summary = "添加优惠卷")
    @PostMapping("/coupon")
    public Result coupon(@RequestBody CouponVo couponVo){
        System.err.println(couponVo);
        this.cardDisplayService.addCoupon(couponVo);
        return Result.success("优惠卷添加成功");
    }

    @DeleteMapping("/coupondelete")
    @Operation(summary = "删除优惠卷")
    public Result coupondelete(@RequestParam("id") Integer id){
        this.cardDisplayService.removeById(id);
        return Result.success("优惠卷删除成功");
    }
}
